package com.shumm.service.impl;

import com.shumm.common.Result;
import com.shumm.mapper.BtcfRelationMapper;
import com.shumm.po.BtcfRelation;
import com.shumm.service.BtcfRelationService;
import com.shumm.vo.btcVo;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BtcfRelationServiceImpl implements BtcfRelationService {

    private BtcfRelationMapper mapper;

    public void setMapper(BtcfRelationMapper btcfRelationMapper) {
        this.mapper = btcfRelationMapper;
    }

    @Override
    public Result add(BtcfRelation btc) {
        return Result.success(mapper.add(btc));
    }

    @Override
    public Result deleteById(Integer id) {
        String message = "处方组成已经删除,请更新页面";
        if (!mapper.isExistedById(id)) {
            mapper.delete(id);
            message = "删除成功";
        }
        return Result.success(message, null);
    }

    @Override
    public Result update(BtcfRelation btc) {
        mapper.update(btc);
        return Result.success();
    }

    @Override
    public Result selectById(Integer id) {
        BtcfRelation btc = mapper.selectById(id);
        return Result.success(btc);
    }


    @Override
    public Result list() {
        List<BtcfRelation> list = mapper.selectAll();
        return Result.success(list);
    }

    @Override
    public Result selectByTbidAndName(String content, String name) {
        List<btcVo> list = mapper.selectByTbidAndName(content, name);
        return Result.success(list);
    }
}
